package java10;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class JdbcTest05 {
        public static void main(String[] args){
            JdbcTest05 jdbc = new JdbcTest05();
            List<Student> list = jdbc.findAll();
            System.out.println(list);
        }
        public List<Student> findAll(){
            Connection conn = null;
            Statement stmt = null;
            ResultSet rs = null;
            List<Student> list = null;
            try {
                conn = JDBCUtils.getConnection();
                stmt = conn.createStatement();
                String sql = "select * from student";
                rs= stmt.executeQuery(sql);
                Student stu = null;
                list = new ArrayList<>();
                while(rs.next()){
                    int id = rs.getInt("id");
                    String name = rs.getString("NAME");
                    int age = rs.getInt("age");
                    String sex = rs.getString("sex");
                    String address = rs.getString("address");
                    int math = rs.getInt("math");
                    int english = rs.getInt("english");
                    stu = new Student();
                    stu.setId(id);
                    stu.setName(name);
                    stu.setAge(age);
                    stu.setSex(sex);
                    stu.setAddress(address);
                    stu.setMath(math);
                    stu.setEnglish(english);
                    list.add(stu);
                }
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }finally {
                JDBCUtils.close(rs,stmt,conn);
            }
            return list;
        }

}
